/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.*;

/**
 * @author Mr Bao
 */
public class HomeScreen extends MIDlet {

    private RegisterForm registerForm;
    private LoginForm loginForm;
    private HomeMain homeMain;
    private AlbumForm albumForm;
    private AddNewAlbumForm addNewAlbumForm;
    private ChoseUploadForm choseUploadForm;
    private ViewAlbumForm viewAlbumForm;
    public Display display;
    private ListImageV2 listImageV2;
    private FileBrowser fileBrowser;
    private  ListImageName listImageName;

    public HomeScreen() {
    }

    public void startApp() {
        try {
            display = Display.getDisplay(this);
            Common.Client = new Client(this);
            DisplayHomeMain();
        } catch (Exception e) {
            Alert alert = new Alert("Error");
            alert.setType(AlertType.ERROR);
            alert.setString("Network error");
            alert.addCommand(new Command("Ok", Command.OK, 2));
            alert.setCommandListener(new CommandListener() {

                public void commandAction(Command c, Displayable d) {
                    destroyApp(true);
                }
            });
            display.setCurrent(alert);
        }
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        notifyDestroyed();
    }
// <editor-fold defaultstate="collapsed" desc="Display">

    public void DisplayListImageName(){
        listImageName = new ListImageName(this);
        display.setCurrent(listImageName);
    }

    public void DisplayListImageNameBack(){
        display.setCurrent(listImageName);
    }

    public void DisplayException(Exception ex) {
        Alert alert = new Alert("Exception");
        alert.setString(ex.getMessage());
        alert.setType(AlertType.ERROR);
        display.setCurrent(alert);
    }

    public void DisplayChoseViewAlbumForm() {
        ChoseViewImageForm choseViewImageForm = new ChoseViewImageForm(this);
        display.setCurrent(choseViewImageForm);
    }

    public void DisplayViewImageForm() {
        ViewImageForm viewImageForm = new ViewImageForm(this);
        display.setCurrent(viewImageForm);
    }

    public void DisplayListImageV2() {
        listImageV2 = new ListImageV2(this);
        display.setCurrent(listImageV2);
    }

    public void DisplayListImageV2Back() {
        display.setCurrent(listImageV2);
    }

    public void DisplayViewAlbumForm() {
        viewAlbumForm = new ViewAlbumForm(this);
        display.setCurrent(viewAlbumForm);
    }

    public void DisplayViewAlbumFormBack() {
        display.setCurrent(viewAlbumForm);
    }

    public void DisplayChoseUploadForm() {
        choseUploadForm = new ChoseUploadForm(this);
        display.setCurrent(choseUploadForm);
    }

    public void DisplayHomeMain() {
        homeMain = new HomeMain(this);
        display.setCurrent(homeMain);
    }

    public void DisplayLoginForm() {
        loginForm = new LoginForm(this);
        display.setCurrent(loginForm);
    }

    public void DisplayRegisterForm() {
        registerForm = new RegisterForm(this);
        display.setCurrent(registerForm);
    }

    public void DisplayAlbumForm() {
        albumForm = new AlbumForm(this);
        display.setCurrent(albumForm);
    }

    public void DisplayAlbumFormBack() {
        display.setCurrent(albumForm);
    }

    public void DisplayAddNewAlbum() {
        addNewAlbumForm = new AddNewAlbumForm(this);
        display.setCurrent(addNewAlbumForm);
    }

    public void DisplayFileBrowser() {
//        ListImage listImage = new ListImage("file:///SDCard/", this);
//        display.setCurrent(listImage);
        fileBrowser = new FileBrowser(this);
        fileBrowser.ShowCurrDir();
    }

    public void DisplayCameraForm() {
        CameraForm cameraForm = new CameraForm(this);
        display.setCurrent(cameraForm);
    }

    public void DisplayError(String errorType) {
        Alert alert = new Alert("Error");
        alert.setString(errorType);
        alert.setType(AlertType.ERROR);
        display.setCurrent(alert);
    }// </editor-fold>
}
